//
//  HomeTableViewController.swift
//  TTWeibo
//
//  Created by 唐磊guang on 16/7/3.
//  Copyright © 2016年 唐磊guang. All rights reserved.
//

import UIKit
import Alamofire
class HomeTableViewController: baseTableViewController,PopoverAnimatorProtocol {
    
    var titleView:TitleButton?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        if !isLogin
        {
            vistorViewa?.setUpVistor(true, imageName: "visitordiscover_feed_image_house", message: "关注一些人，回这里看看有什么惊喜")
            return
        }
        setUpNav()
    }
    //command + control + e批量改名
    private func setUpNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem.creatBarButtonItem("navigationbar_friendattention", taget: self, action: #selector(HomeTableViewController.leftButtonClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem.creatBarButtonItem("navigationbar_pop", taget: self, action: #selector(HomeTableViewController.rightButtonClick))
        let titleView = TitleButton()
        titleView .addTarget(self, action: #selector(HomeTableViewController.titleButtonClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        titleView.setTitle("🍉My Favorite! ", forState: UIControlState.Normal)
        navigationItem.titleView = titleView
        self.titleView = titleView
    }
    
    //Mark --UI事件
    func titleButtonClick(btn: UIButton) {
        
        let st = UIStoryboard(name: "PopoverViewController", bundle: nil)
        let vc = st.instantiateInitialViewController()
        vc?.transitioningDelegate = animator
        vc?.modalPresentationStyle = UIModalPresentationStyle.Custom
        presentViewController(vc!, animated: true, completion: nil)
    }
    func leftButtonClick() {
        print(#function)
    }
    func rightButtonClick() {
        let sb = UIStoryboard(name: "QRCodeViewController", bundle: nil)
        let vc = sb.instantiateInitialViewController()
        presentViewController(vc!, animated: true, completion: nil)
    }
    private lazy var animator:PopoverAnimator = {
        let anima = PopoverAnimator()
        anima.defineFrame = CGRectMake(100, 64, 200, 300)
        anima.delegate = self
        return anima
    }()
    
    //Mark --PopoverAnimatorProtocol
    func presentVCPresent(){
        titleView?.selected = true
    }
    func presentVCDissmiss(){
        titleView?.selected = false
    }
}



